perm filename DISREM.SAI[VIS,HPM]1 blob
sn#250979 filedate 1976-12-03 generic text, type C, neo UTF8
COMMENT ⊗ VALID 00002 PAGES
C REC PAGE DESCRIPTION
C00001 00001
C00002 00002 ENTRY
C00007 ENDMK
C⊗;
ENTRY;
BEGIN "DISREM"
DEFINE MMMM="2";
REQUIRE "ACCEL.SAI[1,DBG]" SOURCE_FILE;
INTEGER PP,PH,MG,MR,M1,M2,M3,M4,M;
INTEGER I,J,K;
COMMENT PQINIT computes several quantities depending on the order of the
polynominals and needed in subsequent calculations;
INTERNAL PROCEDURE PQINIT (INTEGER P,Q);
BEGIN
PP←P;
PH ← (P+1) DIV 2;
MG ← (P+1)*(P+2)%2;
MR ← 0 MAX ((Q+1) DIV 2 - PH);
M1←MG+1;
M2←2*MG;
M3←M2+1;
M4←M3+1;
M←M2+MR
END;
COMMENT DMODEL uses the values of X and Y to compute the coefficients of
the parameters and inserts them into the A and B arrays, which
can be used to obtain the corrections in X and Y, respectively;
SIMPLE PROCEDURE DMODEL (REAL ARRAY A,B; REAL X,Y);
BEGIN
REAL XX,XY,YY,YDX,RR,RRX,RRY;
IF X=0 THEN YDX←0 ELSE YDX←Y/X;
I←1;
A[1]←B[M1]←XX←1;
YY←1;
FOR J←1 STEP 1 UNTIL PP DO
BEGIN
I←I+1;
XX←XX*X;
YY←YY*Y;
A[I]←B[MG+I]←XY←XX;
FOR K←1 STEP 1 UNTIL J-1 DO
BEGIN
I←I+1;
A[I]←B[MG+I]←XY←XY*YDX;
END;
I←I+1;
A[I]←B[MG+I]←YY;
END;
IF MR>0 THEN
BEGIN
RR ← X↑2 + Y↑2;
XY←RR↑PH;
RRX←X*XY;
RRY←Y*XY;
A[M3]←RRX;
B[M3]←RRY;
FOR I←M4 STEP 1 UNTIL M DO
BEGIN
A[I] ← RRX ← RRX*RR;
B[I] ← RRY ← RRY*RR;
END;
END;
END;
COMMENT DISREM uses the distortion calibration coefficients G as computed by
DISCAL to convert the N points XI,YI into the N points XO,YO. (XO and YO
can refer to the same arrays as XI and YI.) If TOL<0, the forward
conversion is done (X,Y to XP,YP in DISCAL). If TOL≥0, the inverse
conversion is done (XP,YP to X,Y in DISCAL), and TOL is the convergence
tolerance (in XO,YO) for terminating the iterations (with a maximum
of 10 iterations). (PQINIT must be called before this procedure to
compute the functions of P and Q, unless this has already been
done by calling DISCAL);
INTERNAL PROCEDURE DISREM (INTEGER N; REAL TOL;
REAL ARRAY G,XI,YI,XO,YO);
BEGIN
OWN REAL ARRAY A,B[1:44];
SAFE OWN REAL ARRAY XY,D[1:2];
REAL XX,YY,TOL2;
INTEGER PNT,ITER;
TOL2←TOL↑2;
FOR PNT←1 STEP 1 UNTIL N DO
BEGIN "POINTS"
XY[1]←XI[PNT];
XY[2]←YI[PNT];
FOR ITER←1 STEP 1 UNTIL 10 DO
BEGIN
DMODEL(A,B,XY[1],XY[2]);
XX←0;
FOR I←1 STEP 1 UNTIL MG, M3 STEP 1 UNTIL M DO
XX ← XX + A[I]*G[I];
YY←0;
FOR I←M1 STEP 1 UNTIL M DO
YY ← YY + B[I]*G[I];
IF TOL<0 THEN
BEGIN
XO[PNT] ← XI[PNT]+XX;
YO[PNT] ← YI[PNT]+YY;
CONTINUE "POINTS";
END
ELSE
BEGIN
XX ← XI[PNT]-XX;
YY ← YI[PNT]-YY;
D[1] ← XX-XY[1];
D[2] ← YY-XY[2];
ACCELERATE(2,XY,D,ITER=1,K);
END;
IF (D[1]↑2+D[2]↑2)<TOL2 THEN DONE;
END;
XO[PNT]←XY[1];
YO[PNT]←XY[2];
END "POINTS";
END "DISREM";
END "DISREM";